<template>
	<view class="pageView">
		<u-loading-page :loading="orderListLoading" bg-color="#e8e8e8"></u-loading-page>
		<u-navbar
			title="服务订单"
			@leftClick="handleLeftClick"
		>
		</u-navbar>
		<view class="tabTopBlock">
			<u-tabs
			  :list="tabList"
				@click="handleTabClick"
				:current="current"
				:activeStyle="{
					fontFamily: 'Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20',
					fontWeight: 'normal',
					fontSize: '30rpx',
					color: '#333333'
				}"
				:inactiveStyle="{
					fontFamily: 'Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20',
					fontWeight: 'normal',
					fontSize: '30rpx',
					color: '#999999'
				}"
				lineColor="#333333"
			></u-tabs>
		</view>
		<view class="tabTopBlock1">
			<u-tabs
			  :list="tabList1"
				:current="current1"
				@click="handleTabClick1"
				lineColor="#fff"
				:inactiveStyle="{
					width: '152rpx',
					height: '60rpx',
					background: '#FFFFFF',
					borderRadius: '78rpx',
					border: '2rpx solid #F4F4F4',
					fontFamily: 'Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20',
					fontWeight: 'normal',
					fontSize: '26rpx',
					color: '#666666',
					display: 'flex',
					justifyContent: 'center',
					alignItems: 'center'
				}"
				:activeStyle="{
					width: '152rpx',
					height: '60rpx',
					background: '#0165FB',
					borderRadius: '78rpx',
					border: '2rpx solid #F4F4F4',
					fontFamily: 'Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20',
					fontWeight: 'normal',
					fontSize: '26rpx',
					color: '#fff',
					display: 'flex',
					justifyContent: 'center',
					alignItems: 'center'
				}"
			></u-tabs>
		</view>
		<view class="listBlock">
			<scroll-view style="height: 77vh;" scroll-y="true" @scrolltolower="handleScrolltolower">
				<view v-for="(item, index) in orderList" :key="index" class="listItem" @click="handleClickOrderItem(item)">
					<view class="listItem-block">
						<view class="listItem-block-title">{{ item.service.name }}</view>
						<view :class="{
							'listItem-block-statuserr': item.state == 0,
							'listItem-block-statusjie': item.state == 1,
							'listItem-block-statusjin': item.state == 2,
							'listItem-block-statuswan': item.state == 3
						}">{{ item.state|handleState }}</view>
					</view>
					<u-divider style="margin: 16rpx 0px;"></u-divider>
					<view class="listItem-ItemContent">
						<view class="listItem-ItemContent-title">就诊医院</view>
						<view class="listItem-ItemContent-val">{{ item.hospital.name }}</view>
					</view>
					<view class="listItem-ItemContent" style="padding-top: 16rpx;">
						<view class="listItem-ItemContent-title">就诊人</view>
						<view class="listItem-ItemContent-val">{{ item.partner.name }}</view>
					</view>
					<view class="listItem-ItemContent" style="padding-top: 16rpx;">
						<view class="listItem-ItemContent-title">手机号</view>
						<view class="listItem-ItemContent-val">{{ item.partner.mobile }}</view>
					</view>
					<view class="listItem-ItemContent" style="padding-top: 16rpx;">
						<view class="listItem-ItemContent-title">期望陪诊时间</view>
						<view class="listItem-ItemContent-val">
							{{ item.service_date|handleServiceDate }} {{ item.service_starttime }}-{{ item.service_endtime }}
						</view>
					</view>
					<view class="listItem-ItemContent" style="padding-top: 16rpx;">
						<view class="listItem-ItemContent-title">特殊需求</view>
						<view class="listItem-ItemContent-val">{{ item.need }}</view>
					</view>
					<u-divider style="margin: 16rpx 0px;"></u-divider>
					<view class="listItem-bottom">
						<view class="listItem-bottom-left">
							<view class="listItem-bottom-left-lefttitle">待支付</view>
							<view class="listItem-bottom-left-priceBlock">
								<text class="listItem-bottom-left-priceBlock-type">¥</text>
								<text>{{ item.amount }}</text>
							</view>
						</view>
						<view class="listItem-bottom-right">
							<button class="listItem-bottom-right-infoBtn">取消订单</button>
							<button class="listItem-bottom-right-primaryBtn">付款</button>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import { pzOrderList } from '@/api/common.js'
	export default{
		data() {
			return {
				current: 0,
				current1: 0,
				orderListLoading: false,
				tabList: [
					{
						name: '陪诊',
						stype: 'pz'
					},
					{
						name: 'VIP定制',
						stype: 'vip'
					},
					{
						name: '代办服务',
						stype: 'db'
					},
					{
						name: '陪护',
						stype: 'ph'
					},
					{
						name: '影像服务',
						stype: 'yx'
					},
					{
						name: '省外陪诊'
					}
				],
				tabList1: [
					{
						name: '全部订单',
						state: '-1'
					},
					{
						name: '待支付',
						state: '0'
					},
					{
						name: '待接单',
						state: '1'
					},
					{
						name: '进行中',
						state: '2'
					},
					{
						name: '已完成',
						state: '3'
					}
				],
				listStype: 'pz',
				serveState: '-1',
				page: 1,
				lastPage: 0,
				orderList: [
					{
						title: '2小时陪诊',
						status: '待支付',
						pitalName: '北京顺义医院',
						username: '周莱来',
						phoneNum: '18807141161',
						dateTime: '2024-09-02 9:30-11:30',
						remark: '暂无',
						price: '128.00'
					}
				]
			}
		},
		filters: {
			handleServiceDate(val) {
				let date = new Date(Number(val))
				let year = date.getFullYear()
				let month = date.getMonth() + 1 > 9 ? date.getMonth() + 1 : '0' + (date.getMonth() + 1)
				let day = date.getDate() > 9 ? date.getDate() : '0' + date.getDate()
				console.log(year, day, month, date)
				return `${year}-${month}-${day}`
			},
			handleState(val) {
				if (val == 0) {
					return '待支付'
				}
				if (val == 1) {
					return '待接单'
				}
				if (val == 2) {
					return '进行中'
				}
				if (val == 3) {
					return '已完成'
				}
			}
		},
		onShow() {
			this.orderList = []
			this.page = 1
			this.getOrderList()
		},
		methods: {
			handleScrolltolower() {
				if (this.page < this.lastPage) {
					this.page++
					this.getOrderList()
				}
			},
			handleLeftClick() {
				uni.switchTab({
					url:'/pages/User/User'
				})
			},
			handleTabClick(e) {
				this.page = 1
				this.orderList = []
				this.listStype = e.stype
				this.current = e.index
				this.getOrderList()
			},
			handleTabClick1(e) {
				this.page = 1
				this.orderList = []
				this.serveState = e.state
				this.current1 = e.index
				this.getOrderList()
			},
			getOrderList() {
				this.orderListLoading = true
				pzOrderList({
					stype: this.listStype,
					state: this.serveState,
					page: this.page
				})
				.then(res => {
					const { code, data } =res
					if (code == '200001') {
						if (this.orderList.length == 0) {
							this.orderList = data.data
						} else {
							this.orderList = this.orderList.concat(data.data)
						}
					}
					this.orderListLoading = false
					this.lastPage = data.last_page
				})
				.catch(e => {
					this.orderListLoading = true
				})
			},
			handleClickOrderItem(item) {
				uni.setStorageSync('orderItem', {
					...item,
					disabled: true,
					url: '/pages/serveOrderPage/serveOrderPage'
				})
				uni.navigateTo({
					url: '/pages/createOrder/createOrder'
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	.pageView{
		width: 100%;
		height: 100vh;
		background: #F4F4F4;
		.tabTopBlock{
			margin-top: 174rpx;
			background: #fff;
		}
		.tabTopBlock1{
			background: #fff;
		}
		.listBlock{
			padding-left: 32rpx;
			padding-right: 32rpx;
			.listItem{
				margin-top: 16rpx;
				padding: 32rpx;
				width: 622rpx;
				background: #FFFFFF;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				&-block{
					display: flex;
					justify-content: space-between;
					align-items: center;
					&-title{
						font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
						font-weight: normal;
						font-size: 32rpx;
						color: #333333;
					}
					&-statuserr{
						font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
						font-weight: normal;
						font-size: 32rpx;
						color: #E5432E;
					}
					&-statusjie{
						font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
						font-weight: normal;
						font-size: 32rpx;
						color: #0165FB;
					}
					&-statusjin{
						font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
						font-weight: normal;
						font-size: 32rpx;
						color: #FF9D43;
					}
					&-statuswan{
						font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
						font-weight: normal;
						font-size: 32rpx;
						color: #999999;
					}
				}
				&-ItemContent{
					display: flex;
					align-items: center;
					justify-content: space-between;
					&-title{
						font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
						font-weight: normal;
						font-size: 24rpx;
						color: #333333;
					}
					&-val{
						font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
						font-weight: normal;
						font-size: 24rpx;
						color: #999999;
					}
				}
				&-bottom{
					display: flex;
					justify-content: space-between;
					align-items: center;
					&-left{
						display: flex;
						align-items: center;
						&-lefttitle{
							font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
							font-weight: normal;
							font-size: 24rpx;
							color: #333333;
						}
						&-priceBlock{
							font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
							font-weight: normal;
							font-size: 40rpx;
							color: #E5432E;
							display: flex;
							align-items: flex-end;
							padding-left: 10rpx;
							&-type{
								font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
								font-weight: normal;
								font-size: 28rpx;
								color: #E5432E;
							}
						}
					}
					&-right{
						display: flex;
						align-items: center;
						&-infoBtn{
							width: 168rpx;
							height: 52rpx;
							border-radius: 32rpx 32rpx 32rpx 32rpx;
							border: 2rpx solid #CCCCCC;
							font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
							font-weight: normal;
							font-size: 24rpx;
							color: #666666;
							display: flex;
							justify-content: center;
							align-items: center;
						}
						&-primaryBtn{
							width: 128rpx;
							height: 52rpx;
							background: linear-gradient( 270deg, #0165FB 0%, #7AA7EB 100%);
							border-radius: 32rpx 32rpx 32rpx 32rpx;
							font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
							font-weight: normal;
							font-size: 24rpx;
							color: #FFFFFF;
							display: flex;
							justify-content: center;
							align-items: center;
							margin-left: 30rpx;
						}
					}
				}
			}
		}
	}
</style>